<template>
  <!-- 配件财务对账单 -->
  <div>
    <TopFilter :list="topFilterList" :cols="4" :collapse="false" @filterChange="changeHandler" />
    <FilterTable
      ref="table"
      columnsRef="partPartOtherPartFinancialStatementIndex"
      :columns="tableColumns"
      :isSelectColumn="false"
      selectionType="single"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.tableColumns = columns)"
    >
    </FilterTable>

    <!-- 对账单详情弹窗 -->
    <BaseDialog :visible.sync="billDetailVisible" destroyOnClose title="编辑对账单" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detial :detail="editData" @close="billDetailVisible = false" @reSearchMain="handleResearchTableData" />
    </BaseDialog>
  </div>
</template>

<script>
import { queryPartFinancialStatementList } from '@/api/part/partOther/partFinancialStatement/index.js';
import { dictionary } from '@/utils/dictMixin';
import { arrayObjDeWeight } from '@/utils/index';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
import detial from './detial';

export default {
  name: 'partPartOtherPartFinacialStatementMain',
  components: {
    detial
  },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      tableColumns: this.createTableColumns(),
      billDetailVisible: false, // 是否显示财务对账单详情
      fetchapi: queryPartFinancialStatementList,
      fetchParams: { xhrAbort: false },
      editData: {} // 编辑的数据
    };
  },
  mounted() {
    this.getDealerUser();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '下发日期',
          fieldName: 'alodatBeg|alodatEnd'
        },
        {
          type: 'SELECT',
          label: '上传状态',
          fieldName: 'isUpload',
          itemList: this.createDictList(9708)
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          width: 80,
          dataIndex: 'action',
          render: params => {
            return (
              <el-button
                type="text"
                onClick={() => {
                  this.handleEdit(params.row);
                }}
              >
                编辑
              </el-button>
            );
          }
        },
        {
          title: '序号',
          width: 60,
          dataIndex: 'pIndex',
          render: params => {
            return <span>{params.row.$index + 1}</span>;
          }
        },
        {
          title: '下发日期',
          dataIndex: 'alodat'
        },
        {
          title: '经办人',
          dataIndex: 'handlePerson',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '处理状态',
          dataIndex: 'status',
          render: params => {
            return <span>{params.row.status == '1' ? '记录相符' : '记录不符'}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'remarks'
        },
        {
          title: '上传',
          dataIndex: 'isUpload',
          render: params => {
            return <span>{this.createDictText(params.row.isUpload, '9708')}</span>;
          }
        },
        {
          title: '处理日期',
          dataIndex: 'updatedAt',
          dateFormat: 'yyyy-MM-dd '
        }
      ];
    },
    // 顶部搜索条件搜索或重置
    changeHandler(e) {
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign(this.fetchParams, {
        ...e,
        xhrAbort: false
      });
    },
    // 获取人员数据接口
    async getDealerUser() {
      const res = await getDealerUser();
      let salerResult = arrayObjDeWeight(res.data, 'userId');
      this.tableColumns.find(x => x.dataIndex === 'handlePerson').editItems = salerResult.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    },
    // 点击行项编辑
    handleEdit(e) {
      this.editData = e;
      this.billDetailVisible = true;
      console.log(e);
    },
    // 重新查询table数据
    handleResearchTableData() {
      this.fetchParams.xhrAbort = true;
      this.fetchParams.xhrAbort = false;
    }
  }
};
</script>
